<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title></title>
  <link href="../css/mui.min.css" rel="stylesheet" />
    
</head>
<body>
     <header class="mui-bar mui-bar-nav">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
            <h1 class="mui-title">支付测试</h1>
        </header>
        <div class="mui-content">
        	
        	
        	
        	
            <input type="button" class="btn btn-lg" id="pay" value="微信支付" onclick="pay('wxpay')" />
            
            
            
        </div>
        <script src="../js/jquery.min.js" type="text/javascript" charset="utf-8"></script>
         <script src="../js/mui.min.js"></script>
         <script src="../js/req.js" type="text/javascript" charset="utf-8"></script>
         <script src="../js/muishow.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">

var channel = null;
var channels = null;
window.onload = function(){
	mui.init();
	
	
	
}
function setpopup(data){
				let list = {
					url:"/api/Address/address_list",
					data:{access_token:acctoken()}
				}
				ajax(list,function(res){
					console.log(res);
					let addstr = "暂无地址，点击设置";
					for(let i = 0; i < res.data.length;i++){
						if(res.data[i].status == 1){
							addid = res.data[i].id;
							addstr = res.data[i].province+' '+res.data[i].city+' '+res.data[i].county+' '+res.data[i].address;
						}
					}
					console.log(addstr);
				let pstr = '<div class="ws_details_close ws_close hide"></div>'+
						'<div class="ws_details_cover"><div class="ws_details_header"><div class="ws_img_wrap ws_100">'+
						'<img src="'+hurl+'/uploads'+data.book_image+'" alt="" />'+
						'</div><div class="ws_main"><div><span class="ws_details_price">'+
						data.price+
						'</span> <i class="mui-icon ws_close mui-icon-close mui-pull-right"></i></div>'+
						'</div></div><div class="ws_details_footer">'+
						'<div class="ws_details_adds" onclick="goaddss()">'+
						'<i class="mui-icon mui-icon-location"></i><span>'+
						addstr+
						'</span><i class="mui-icon mui-icon-arrowright mui-pull-right"></i>'+
						'</div><div class="ws_sum">购买数量'+
						'<div class="mui-numbox ws_sum_btn"  data-numbox-min="1" data-numbox-max="100">'+
						'<button class="mui-btn mui-numbox-btn-minus" type="button">-</button>'+
						'<input class="mui-numbox-input" type="number" id="inputvalue" />'+
						'<button class="mui-btn mui-numbox-btn-plus" type="button">+</button>'+
						'</div></div>'+
						'<div class="mui-input-row"><label>备注</label>'+
						'<input type="text" id="beizhuid" placeholder="请输入备注"></div>'+
						'</div><div class=" ws_play determine hide" onclick="buybook()">确定</div></div>';
				
				g("popdiv").innerHTML = pstr;
				
				mui('.mui-numbox').numbox(); 
				$(".ws_close").click(function(){
					$(".determine").addClass("hide");
					$(".ws_details_close").addClass("hide");
					$(".ws_details_popup").stop(true,true).animate({top:"100%"},400);
				})
				})
			}


             // 1. 获取支付通道
            function plusReady() {
                // 获取支付通道
                plus.payment.getChannels(function(cs) {
                    channels = cs;
                   
                },
                function(e) {
                    alert("获取支付通道失败：" + e.message);
                });
            }
            document.addEventListener('plusready', plusReady, false);
    var WXPAYSERVER = 'http://demo.dcloud.net.cn/payment/?payid=wxpay&appid=HBuilder&total=1';
             // 2. 发起支付请求
            function pay(id) {
                // 从服务器请求支付订单
                var PAYSERVER = '';
             if (id == 'wxpay') { PAYSERVER = WXPAYSERVER; }
               console.log("id==>"+id);
             console.log("payserver==>"+WXPAYSERVER);
               for (var i in channels)
                {
                    if (channels[i].id == id) 
                    {
                       channel = channels[i];
                  }
                }
                mui.get(PAYSERVER, function(data) {
                  
                    plus.payment.request(channel, varpay, function(result) {
                        plus.nativeUI.alert("支付成功！", function() {
                            back();
                        });
                    }, function(e) {
                        plus.nativeUI.alert("支付失败：" + e.code + "支付失败：" + e.message);
                        console.log(e.code);
                        console.log(e.message);
                    });
                }, "json");
				
            }
    </script>
</body>
</html>